#include <iostream>

using namespace std;

struct TreeNode
{
	int val;
	TreeNode* left;
	TreeNode* right;

	TreeNode(int x)
		:val(x)
		, left(nullptr)
		, right(nullptr)
	{}
	TreeNode(int x, TreeNode* _left, TreeNode* _right)
		:val(x)
		, left(_left)
		, right(_right)
	{}
};

class Solution 
{
public:
	long pre = INT_MIN;
	bool isValidBST(TreeNode* root) 
	{
		if (!root)
			return true;
		if (!isValidBST(root->left))
			return false;
		if (pre >= root->val)
		{
			return false;
		}
		pre = root->val;
		if (!isValidBST(root->right))
			return false;
		return true;
	}
};


int main()
{
	TreeNode* A = new TreeNode(2);
	TreeNode* B = new TreeNode(3);
	TreeNode* root = new TreeNode(1, A, B);

	Solution xz;
	int n = xz.isValidBST(root);
	cout << n << endl;

	return 0;
}